﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Administrator_AdminControl_ApprovalBusiness : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            LoadInfo();
    }

    private void LoadInfo()
    {
        try
        {
            using (Up1VNDataContext dc = new Up1VNDataContext())
            {
                var query = (from o in dc.EStores where o.EStore_StatusId != 2
                             select o).ToList();
                if (query.Count > 0)
                {
                    PagedDataSource page = new PagedDataSource();
                    page.AllowCustomPaging = true;
                    page.AllowPaging = true;
                    page.DataSource = query;
                    rptInfo.DataSource = page;
                    rptInfo.DataBind();
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void rptInfo_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        using (Up1VNDataContext db = new Up1VNDataContext())
        {
            drdJob.Items.Clear();
            
            pnlDetail.Visible = true;
            var query = (from o in db.EStores where o.EStore_Id == int.Parse(e.CommandArgument.ToString()) select o).Single();
            lblName.Text = query.EStore_Name;
            txtName.Text = query.EStore_Name;
            txtTax.Text = query.EStore_CodeTax;
            txtRepresent.Text = query.EStore_Representative;
            txtPhone.Text = query.Estore_HomePhone;
            txtMobil.Text = query.EStore_MobilePhone;
            txtSky.Text = query.EStore_NickSkype;
            txtYahoo.Text = query.EStore_NickYahoo;
            txtAddress.Text = query.EStore_Address;
            txtDes.Text = query.EStore_BriefIntroduction;
            txtWeb.Text = query.EStore_Website;
            txtFax.Text = query.EStore_Fax;


            var queryCateJob = (from o in db.GeneralCategories where o.GeneralCategory_Id == query.EStore_CategoryId select o).Single();
            drdJob.Items.Add(queryCateJob.GeneralCategory_Name.ToString());

            var queryCateCity = (from o in db.GeneralCategories where o.GeneralCategory_Id == query.EStore_ProvinceId select o).Single();
            drdCity.Items.Add(queryCateCity.GeneralCategory_Name.ToString());

            lblEstoreID.Text = query.EStore_Id.ToString();
        }
    }
    protected void btnAgree_Click(object sender, EventArgs e)
    {
        try
        {
            int id = int.Parse(lblEstoreID.Text);
            using (Up1VNDataContext db = new Up1VNDataContext())
            {
                EStore E = db.EStores.Single(s => s.EStore_Id == id);
                E.EStore_StatusId = ApprovedSettingType.Active;

                db.SubmitChanges();
                LoadInfo();
                pnlDetail.Visible = false;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void btnNotAgree_Click(object sender, EventArgs e)
    {
        try
        {
            int id = int.Parse(lblEstoreID.Text);
            using (Up1VNDataContext db = new Up1VNDataContext())
            {
                EStore E = db.EStores.Single(s => s.EStore_Id == id);
                E.EStore_StatusId = ApprovedSettingType.NotAgree;

                db.SubmitChanges();
                LoadInfo();
                pnlDetail.Visible = false;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        pnlDetail.Visible = false;
    }
}